<?php
/**
 * 动态
 * Author: 毛康燕
 * Date: 2021/6/17
 */
namespace app\api\controller\v1;

use app\common\model\Dynamic as DynamicModel;

class Dynamic extends BaseController
{

    //真实动态
    public function dynamic()
    {
        $model = new DynamicModel();
        $page = input('page/d', 1);
        //小轮播
        $ban = $model
            ->where('type', 3)
            ->field('id,image,title')
            ->page($page, 3)
            ->select()
            ->toArray();
        $ban = addWebSiteUrl($ban, ['image']);
        //上部分
        $top = $model
            ->where('type', 3)
            ->field('id,image,title,content')
            ->page($page, 4)
            ->select()
            ->toArray();
        $top = addWebSiteUrl($top, ['image']);
        //下部分
        $but = $model
            ->where('type', 4)
            ->field('id,image,title,content')
            ->page($page, 3)
            ->select()
            ->toArray();
        $but = addWebSiteUrl($but, ['image']);
        $count = $model
            ->where('type',4)
            ->field('id')
            ->count();
        $maxpage = ceil($count / 3);
        $total = count($but);
        return sucessMsg(200, '获取成功！', [
                'ban' => $ban,
                'top' => $top,
                'but' => $but,
                'total'=>$total,
                'count'=>$count,
                'maxpage'=>$maxpage
            ]);
    }

    //真实动态详情
    public function dynamicCate()
    {
        $data = input('id');
        if (empty($data)) {
            return errMsg(422, '请输入id');
        }
        $model = new DynamicModel();
        $list = $model
            ->where('id', $data)
            ->field('id,keyword,source,edit,created_at,content')
            ->find();
        if (empty($list)) {
            return errMsg(422, '找不到数据');
        }
        $list['content'] = chancontent($list['content']);
        return sucessMsg(200, '详情获取成功！', ['list' => $list]);
    }
}